package ui.units {

	import flash.display.Sprite;
	import flash.geom.Point;
	
	public class Magic extends BaseUnit{
		
		public var angle:Number;
		public var start:Point;
		public var end:Point;
		public var target:Object;
		public var speed:Number;
		
		public function Magic(){
			super();
		}
		
		override public function init(bean:UnitBean):void {
			super.init(bean);
		}
		
		override public function update():void {
			super.update();
			if (target != null) {
				end.x = target.x;
				end.y = target.y;
			}
			if (end == null) {
				return;
			}
			var angle:Number = Math.atan2(end.y - start.y, end.x - start.x);
			var dx:Number = speed * Math.cos(angle);
			var dy:Number = speed * Math.sin(angle);
			if (x - end.x < dx) {
				x = end.x;
			} else {
				x += dx;
			}
			if (y - end.y < dy) {
				y = end.y;
			} else {
				y += dy;
			}
		}
	}
}